import 'package:flutter/cupertino.dart';

List<String> detailTextList = [
  '哆啦A梦',
  '小倩',
  '生生',
  '粥粥',
  '骅骅',
  '生意',
  '生火',
  '生儿子'
];

class SearchVM extends ChangeNotifier {
  /// 返回搜索结果的数组
  List<String> _keyWordList = [];

  /// 用户搜索关键字
  String _keyWord;

  List<String> get keyWordList => _keyWordList;

  String get keyWord => _keyWord;

  ///关键字是否在数组里面有包含,有的话返回搜索结果赋值给数组.
  onChangedText({String text}) {
    if (text.length > 0) {
      _keyWord = text;
      _keyWordList = detailTextList
          .where((detailTextList) => detailTextList.contains(text))
          .toList();
    } else {
      _keyWord = null;
      _keyWordList = [];
    }
    notifyListeners();
  }

  ///取消清空搜索关键字
  remoDetail() {
    if (_keyWordList.length > 0) {
      _keyWordList = [];
    }
    notifyListeners();
  }
}
